﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.LogicalGroups.CApLGRLogicalGroupsUtil
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections;
using System.Text;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.LogicalGroups;

internal class CApLGRLogicalGroupsUtil
{
  internal static TxObjectList GetAllLogicalGroups()
  {
    TxObjectList allLogicalGroups = (TxObjectList) null;
    if (CApLGRLogicalGroupsUtil.IsDataLoaded())
      allLogicalGroups = TxApplication.ActiveDocument.LogicalRoot.GetDirectDescendants((ITxTypeFilter) new TxTypeFilter(typeof (TxLogicalGroup)));
    return allLogicalGroups;
  }

  internal static TxObjectList GetLogicalGroupsFromSelection()
  {
    TxObjectList groupsFromSelection = (TxObjectList) null;
    if (CApLGRLogicalGroupsUtil.IsDataLoaded())
      groupsFromSelection = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(typeof (TxLogicalGroup)));
    return groupsFromSelection;
  }

  internal static bool IsDataLoaded()
  {
    bool flag = false;
    if (TxTcUtilities.IsTcAnyPlatform)
      flag = TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded();
    else if (TxApplication.ActiveDocument.CurrentStudy != null)
      flag = true;
    return flag;
  }

  internal static TxPlanningTypeMetaData GetTypeMetaData(string planningType)
  {
    TxPlanningTypeMetaData typeMetaData = (TxPlanningTypeMetaData) null;
    if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      typeMetaData = TxApplication.ActiveDocument.PlatformGlobalServicesProvider.GetTypeMetaData(planningType);
    return typeMetaData;
  }

  internal static bool IsSubComponent(ITxObject obj)
  {
    bool flag = false;
    if (obj is ITxComponent itxComponent && ((ITxObject) itxComponent).Collection is ITxComponent)
      flag = true;
    return flag;
  }

  internal static ITxPlanningObject GetPlanningRepresentation(ITxObject obj)
  {
    switch (obj)
    {
      case ITxProcessModelObject processModelObject:
        pattern_0 = processModelObject.PlanningRepresentation;
        break;
    }
    return pattern_0;
  }

  public static string ConvertArrayListToString(ArrayList objects)
  {
    StringBuilder stringBuilder = new StringBuilder();
    if (objects != null && objects.Count > 0)
    {
      stringBuilder.Append(objects[0].ToString());
      for (int index = 1; index < objects.Count; ++index)
      {
        stringBuilder.Append(", ");
        stringBuilder.Append(objects[index].ToString());
      }
    }
    return stringBuilder.ToString();
  }

  public static string ConvertTransformationToString(TxTransformation transPropertyValue)
  {
    StringBuilder stringBuilder = new StringBuilder();
    int afterDecimalPoint = TxApplication.Options.Units.LinearDigitsAfterDecimalPoint;
    if (TxTransformation.op_Inequality(transPropertyValue, (TxTransformation) null))
    {
      TxVector translation = transPropertyValue.Translation;
      TxVector rotationRpyXyz = transPropertyValue.RotationRPY_XYZ;
      stringBuilder.Append('{');
      stringBuilder.Append(translation.ToString(afterDecimalPoint));
      stringBuilder.Append("} {");
      stringBuilder.Append(rotationRpyXyz.ToString(afterDecimalPoint));
      stringBuilder.Append('}');
    }
    return stringBuilder.ToString();
  }

  public static string ConcatStringsWithDot(string left, string right)
  {
    string str = string.Empty;
    if (left.Length > 0 && right.Length > 0)
      str = $"{left}.{right}";
    return str;
  }

  public static bool IsPrototypeAssignment(ITxObject obj)
  {
    return CApLGRLogicalGroupsUtil.GetPlanningRepresentation(obj) is TxPlanningPrototypeAssignment;
  }

  public static TxObjectList GetCompoundChildrenOfGroup(TxLogicalGroup txGroup)
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxCompoundResource));
    txTypeFilter.AddIncludedType(typeof (TxCompoundPart));
    return txGroup.GetAllDescendants((ITxTypeFilter) txTypeFilter);
  }

  public static bool IsChildOrGripFrame(ITxObject obj)
  {
    bool flag = false;
    if (obj is TxFrame)
    {
      TxFrame txFrame = obj as TxFrame;
      if (!(txFrame.Collection is TxPhysicalRoot) || TxEngineeringDataInternal.IsGripFrame((ITxObject) txFrame))
        flag = true;
    }
    return flag;
  }
}
